"use strict"

var path = require('path')
var util = require('../libs/util')
var Wechat = require('../wechat/wechat')
var wechat_file = path.join(__dirname,'../config/wechat.txt')
var wechat_ticket_file = path.join(__dirname,'../config/wechat_ticket.txt')
var config = {
	wechat: {
		appID:'wx1028b6d8dae61060',
		appSecret:'d90650181143e5bb2158be64cc21de9d',
		token:'086430ffed2bd132894c2b6228943cd3',
		getAccessToken:function () {
			return util.readFileAsync(wechat_file)
		},
		saveAccessToken:function(data){
			data = JSON.stringify(data)
			return util.writeFileAsync(wechat_file,data)
		},
		getTicket:function () {
			return util.readFileAsync(wechat_ticket_file)
		},
		saveTicket:function(data){
			data = JSON.stringify(data)
			return util.writeFileAsync(wechat_ticket_file,data)
		}
	}
} 

exports.wechatOptions = config

exports.getWechat = function(){
	var wechatApi = new Wechat(config.wechat)

	return wechatApi
}